package com.atguigu.guli.edu.controller;

import java.util.Arrays;
import java.util.Map;

import com.atguigu.common_utils.utils.PageUtils;
import com.atguigu.common_utils.utils.R;
import com.atguigu.guli.edu.entity.Teacher;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atguigu.guli.edu.service.EduTeacherService;




/**
 * 讲师
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-01-19 10:59:18
 */
@Api(tags = "讲师管理模块")
@RestController
@RequestMapping("edu/eduteacher")
public class EduTeacherController {
    @Autowired
    private EduTeacherService eduTeacherService;



    /**
     * 添加讲师
     */
    @ApiOperation(value = "添加讲师")
    @PostMapping("add")
    public R addTeacher(@RequestBody Teacher eduTeacherEntity){
        eduTeacherService.addTeacher(eduTeacherEntity);
        return R.ok();
    }

    /**
     * 分页条件查询
     * map 封装的查询参数和当前页码
     * id    教师id
     */
    @ApiOperation(value = "条件分页查询")
    @GetMapping("/page")
    public R pageSelect(@RequestParam(required = false) Map<String,Object> parms){
        PageUtils pageUtils = eduTeacherService.pageSelect(parms);

        return R.ok().put("data",pageUtils);
    }

    /**
     * 逻辑删除讲师
     */
    @ApiOperation(value="逻辑删除")
    @DeleteMapping("/delete/{id}")
    public R deleteId(@PathVariable String id){
        try {
            eduTeacherService.deleteId(id);
            return R.ok();
        } catch (Exception e) {
            return R.error();
        }
    }

    /**
     * 列表
     */
//    @ApiOperation(value = "讲师列表")
//    @GetMapping("/list")
//    //@RequiresPermissions("edu:eduteacher:list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = eduTeacherService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }


    /**
     * 信息
     */
    @ApiOperation("根据路径id查询讲师信息")
    @GetMapping("/info/{id}")
    //@RequiresPermissions("edu:eduteacher:info")
    public R info(@PathVariable("id") String id){
        Teacher eduTeacher = eduTeacherService.getById(id);

        return R.ok().put("eduTeacher", eduTeacher);
    }

    /**
     * 保存
     */
    @ApiOperation("添加讲师")
    @PostMapping("/save")
    public R save(@RequestBody Teacher eduTeacher){
		eduTeacherService.save(eduTeacher);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value ="修改讲师" )
    @PutMapping("/update")
    //@RequiresPermissions("edu:eduteacher:update")
    public R update(@RequestBody Teacher eduTeacher){
		eduTeacherService.updateById(eduTeacher);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("删除讲师")
    @DeleteMapping("/delete")
    //@RequiresPermissions("edu:eduteacher:delete")
    public R delete(@RequestBody String[] ids){
		eduTeacherService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
